/**
 * Created by Sultan Imanhodjaev.
 * User: sultan
 * Date: 3/24/11
 * Time: 6:49 PM
 */

$(document).ready(function() {
    var st = {}

    $('.link-tools, #id_add_link img').mouseover(function() {
        var p = $(this).attr('src');
        var r = $(this).attr('rel');

        $(this).attr('src', p.replace('color', 'grey'));

        st['td[rel="' + r + '"]'] = $('td[rel="' + r + '"]').css('background')

        $('td[rel="' + r + '"]').css({
            'text-decoration': 'underline'
        });
    }).mouseout(function() {
        var p = $(this).attr('src');
        var r = $(this).attr('rel');

        $(this).attr('src', p.replace('grey', 'color'));

        st[r] = $('td[rel="' + r + '"]').css('background')

        $('td[rel="' + r + '"]').css({
            'background': st[r],
            'text-decoration': 'none'
        });
    });

    function testing(data) {
        var content = '<div>';

        if ($('#modal').length == 0) {
            var el = document.createElement('div');

            $(el).attr('id', 'modal');
        }

        for (meta in data['data'][0]) {
            console.log(meta + ':' + data['data'][0][meta]);

            content += '<div>' + meta + ':' + data['data'][0][meta] + '</div>';
        }

        $(el).html(content + '</div>');

        $.facebox(content, {
            'width': 500
        });
    }

    $('.check-link').click(function(e) {
        console.log($(this).attr('rel'));
        Dajaxice.core.check_link(testing, {'link': $(this).attr('rel')});

        return false;
    });
});
